#include <tuple>
#include <iostream>

auto get_student(int id)
{
  // 返回类型被推断为 std::tuple<double, char, std::string>
  if (id == 0)
    return std::make_tuple(3.8, 'A', " 张三");

  if (id == 1)
    return std::make_tuple(2.9, 'C', " 李四");

  if (id == 2)
    return std::make_tuple(1.7, 'D', " 王五");

  return std::make_tuple(0.0, 'D', "null");
  // 如果只写 0 会出现推断错误, 编译失败
}

int main()
{
  auto student = get_student(0);

  std::cout << "ID: 0, "
  << "GPA: " << std::get<0>(student) << ", "
  << " 成绩: " << std::get<1>(student) << ", "
  << " 姓名: " << std::get<2>(student) << std::endl;

  double gpa;
  char grade;
  std::string name;

  // 元组进行拆包
  std::tie(gpa, grade, name) = get_student(1);

  std::cout << "ID: 1, "
  << "GPA: " << gpa << ", "
  << " 成绩: " << grade << ", "
  << " 姓名: " << name << std::endl; 

  // C++20 feature
  // int i = 1;
  // std::cout << tuple_index(student, i) << std::endl; 

}